import axios from "axios";
import NProgress from "nprogress";
import "nprogress/nprogress.css"

// 创建实例对象
let instance = axios.create({
    baseURL: "/sph",   // 默认域名
    timeout: 5000   // 超时时间
})

// 请求拦截
instance.interceptors.request.use((config)=>{
    NProgress.start()  //开启进度条
    return config
})

// 响应拦截
instance.interceptors.response.use(
    (response)=>{
        NProgress.done()  //关闭进度条
        switch(response.data.code){
            case 200:
                return response.data.data
            default:
                return response.data
        }
    },
    (error)=>{
        NProgress.done()  //关闭进度条
        console.log(error.message);
        return new Promise(()=>{})
    }
)
export default instance